#include "shaderMgr.h"

cShaderMgr mShaderMgr;
cShaderMgr* GetShaderMgr()
{
	return &mShaderMgr;
}

void cShaderMgr::PushShader(WCHAR* shaderPath,string shaderKey)
{
	m_pDevice9 = GetDevice9();
	ID3DXEffect* pEffect;
	ID3DXBuffer* pError;
	if(mapShader.find(shaderKey)!=mapShader.end())
		return;
	D3DXCreateEffectFromFile(m_pDevice9,shaderPath,NULL,NULL,D3DXSHADER_DEBUG,NULL,&pEffect,&pError);
	if(pError)
	{
		ERRBOX((char*)pError->GetBufferPointer());
	}
	mapShader.insert(make_pair(shaderKey,pEffect));
}

ID3DXEffect* cShaderMgr::GetShader(string shaderKey)
{
	if(mapShader.find(shaderKey)!=mapShader.end())
	{
		return mapShader[shaderKey];
	}
	return NULL;
}

void cShaderMgr::ReleaseAll()
{
	auto itr = mapShader.begin();
	while(itr!=mapShader.end()){
		itr->second->Release();
	}
}